<?php
namespace app\api\controller;

use think\Controller;
use app\api\model\Postdatadb;
use app\erp\model\Orderdb;
use app\erp\model\Shoppingdb;
use app\erp\model\Invoicedb;
use app\erp\model\Cartdb;
use app\erp\model\Goodsdb;

class Henan extends Controller
{

    protected $ys_config = [
        'geteway' => 'http://api.utecbj.com/erp/api/',
        'partnerId' => 25,
        'siteId' => 10,
        'appId' => 'utec',
        'appKey' => 'yserp',
        'appSecret' => 'duXtRelcYy2sJeqrLpmNvbQO0O0OO0O0O'
    ];

    protected $ys_username = 'henan_admin';

    protected $ys_password = '12345678';

    protected $member_id = 56;

    protected $site_url = 'http://gd.hy.utecbj.com/';

    public $wsdl = 'http://222.143.21.205:8099/wsscservices/services/wsscWebService?wsdl';

    public $soap_client;

    public $username = '13582';

    public $pwd = '949d6a7ead4bba38e0535b04080a6957';

    public $request = array();

    public function _initialize()
    {
        header("Access-Control-Allow-Origin: *");
        header('Content-Type:application/json; charset=utf-8');
        $this->soap_client = new \SoapClient($this->wsdl);
        $this->request = request()->param();
    }

    public function getFunction()
    {
        $res = $this->soap_client->__getFunctions();
        dump($res);
    }
    // 商品列表 3.1
    public function getGoods()
    {
        ini_set('default_socket_timeout', 300);
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['sprkkssj'] = date('YmdHis', time() - 360 * 86400);
        $post_data['sprkJssj'] = date('YmdHis', time());
        $post_data['pageSize'] = 50;
        if (isset($this->request['pageNum'])) {
            $post_data['pageNum'] = $this->request['pageNum'];
        } else {
            $post_data['pageNum'] = 1;
        }
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->findSprkandParam($data);
        $get_data = json_decode($res->out, true);
        if($get_data['resultFlag'] == 'N'){
            dump($get_data);
            exit();
        }
        foreach ($get_data['spList'] as $key => $val) {
            $add_data = array();
            $add_data['goods_unit'] = '件';
            $add_data['goods_name'] = $val['pmmc'] . '_' . $val['xhmc'];
            $add_data['category_api'] = $val['lbbh'];
            $add_data['brand_sign'] = $val['ppmc'];
            $add_data['goods_model'] = $val['xhmc'];
            $add_data['sale_state'] = $val['zt'] == 2 ? 1 : 2;
            $add_data['audit_state'] = 1;
            $add_data['category_attr'] = $val['parametersList'];
            $add_data['site_id'] = $this->ys_config['siteId'];
            $add_data['last_sale_state'] = $add_data['sale_state'];
            $add_data['out_goods_sku'] = $val['xhbh'];
            $add_data['api_option'] = $val;
            $param = array(
                'param' => $add_data
            );
            $return = $this->sendInfo('addHenanGoods', $param);
            if ($return['msg'] != 'success') {
                echo $add_data['goods_name'] . '[' . $return['msg'] . ']，名称：' . $val['pmmc'] . '<br />';
            } else {
                echo $add_data['goods_name'] . '[采集成功]<br />';
                // 采集配件
                $this->getSPPJ($val['pmbh'], $return['data']);
                // 采集服务
                $this->getFW($val['pmbh'], $return['data']);
            }
        }
        if ($get_data['pagecount'] > $post_data['pageNum']) {
            echo '3秒钟后采集下一页;';
            $url = url('henan/getGoods', array(
                'pageNum' => ($post_data['pageNum'] + 1)
            ));
            header("Refresh:3;url=" . $url);
        }
    }
    // 商品配件 3.2
    public function getSPPJ($pmbh, $goods_sku)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['pmbh'] = $pmbh;
        $post_data['pageNum'] = 1;
        $post_data['pageSize'] = 50;
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->findPjByPmbh($data);
        $get_data = json_decode($res->out, true);
        echo '配件信息：';
        if ($get_data['resultFlag'] == 'N') {
            echo $get_data['resultMessage'] . '<br />';
        } else {
            $param = array();
            foreach ($get_data['accessoryList'] as $key => $val) {
                $param[$key]['site_id'] = $this->ys_config['siteId'];
                $param[$key]['goods_sku'] = $goods_sku;
                $param[$key]['accessory_name'] = $val['PJMC'];
                $param[$key]['accessory_sign'] = $val['PJBH'];
                $param[$key]['accessory_intro'] = $val['PJMS'];
                $param[$key]['accessory_param'] = $val['accessoryListmx'];
                $param[$key]['accessory_api'] = $val;
                $param[$key]['last_accessory_price'] = 0;
                $param[$key]['accessory_price'] = 0;
            }
            if (count($param) > 0) {
                $post_param['param']['goods_sku'] = $goods_sku;
                $post_param['param']['data'] = $param;
                $post_param['param']['site_id'] = $this->ys_config['siteId'];
                $return = $this->sendInfo('addHenanAccessory', $post_param);
            }
            echo '配件信息采集完成<br />';
        }
    }
    // 获取增值服务 3.3
    public function getFW($pmbh, $goods_sku)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['pmbh'] = $pmbh;
        $post_data['pageNum'] = 1;
        $post_data['pageSize'] = 10;
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->findFwByPmbh($data);
        $get_data = json_decode($res->out, true);
        echo '服务信息：';
        if ($get_data['resultFlag'] == 'N') {
            echo $get_data['resultMessage'] . '<br />';
        } else {
            $param = array();
            foreach ($get_data['serviceList'] as $key => $val) {
                $temp['site_id'] = $this->ys_config['siteId'];
                $temp['goods_sku'] = $goods_sku;
                $temp['service_sign'] = $val['FWBH'];
                $temp['service_name'] = $val['FWMC'];
                $temp['service_intro'] = $val['FWMX'];
                $temp['service_state'] = $val['ZT'];
                $temp['service_api'] = $val;
                $temp['last_service_price'] = 0;
                $temp['service_price'] = 0;
                array_push($param, $temp);
            }
            if (count($param) > 0) {
                $post_param['param']['goods_sku'] = $goods_sku;
                $post_param['param']['data'] = $param;
                $post_param['param']['site_id'] = $this->ys_config['siteId'];
                $return = $this->sendInfo('addHenanService', $post_param);
            }
            echo '服务信息采集完成<br />';
        }
    }
    // 商品报价 3.4
    public function sendGoodsPrice($goods_info)
    {
        if ($goods_info['sale_state'] == false) {
            // 销售状态改变
            $this->goodsDown($goods_info);
            sleep(1);
        } else {
            $this->goodsUp($goods_info);
        }
        if ($goods_info['sale_state'] == false) {
            echo '商品下架，不需要推送价格信息' . chr(13);
            exit();
        }
        echo '商品报价：' . chr(13);
        $api_price = floatval($goods_info['sale_price_info']['data'][0]['api_price']);
        $last_api_price = floatval($goods_info['sale_price_info']['data'][0]['last_api_price']);
        if ($api_price == $last_api_price) {
            echo '商品价格没变，不用推送<br />';
        } else {
            if ($api_price > $last_api_price) {
                $jgsfyy = '正常报价';
            } else {
                $jgsfyy = '成本上涨';
            }
            $post_data['username'] = $this->username;
            $post_data['pwd'] = $this->hashMd5();
            $post_data['xhbh'] = $goods_info['goods_api_option']['xhbh'];
            $post_data['xhmc'] = $goods_info['goods_api_option']['xhmc'];
            $post_data['pmbh'] = $goods_info['goods_api_option']['pmbh'];
            $post_data['pmmc'] = $goods_info['goods_api_option']['pmmc'];
            $post_data['ppbh'] = $goods_info['goods_api_option']['ppbh'];
            $post_data['ppmc'] = $goods_info['goods_api_option']['ppmc'];
            $post_data['lbbh'] = $goods_info['goods_api_option']['lbbh'];
            $post_data['lbmc'] = $goods_info['goods_api_option']['lbmc'];
            $post_data['sjjg'] = $api_price;
            $post_data['fwcn'] = '北京优士创新科技发展有限公司';
            $post_data['productlink'] = 'http://hn.mall.utecbj.com/';
            $post_data['jgsfyy'] = $jgsfyy;
            $data['in0'] = json_encode($post_data);
            $res = $this->soap_client->execute($data);
            $get_data = json_decode($res->out, true);
            echo $get_data['resultMessage'] . '<br />';
        }
        sleep(1);
        $this->sendAccessoryPrice($goods_info);
        sleep(1);
        $this->sendServicePrice($goods_info);
        $this->goodsUp($goods_info);
        sleep(1);
    }
    // 配件报价 3.5
    public function sendAccessoryPrice($goods_info)
    {
        echo '配件报价：<br />';
        if (! isset($goods_info['goods_accessory'])) {
            echo '没有配件报价';
        } else {
            $accessory_option = $goods_info['goods_accessory'];
            foreach ($accessory_option as $key => $val) {
                if (floatval($val['accessory_price']) != floatval($val['last_accessory_price'])) {
                    if (floatval($val['accessory_price']) > floatval($val['last_accessory_price'])) {
                        $jgsfyy = '正常报价';
                    } else {
                        $jgsfyy = '成本上涨';
                    }
                    $accessory_api = json_decode($val['accessory_api'], true);
                    $post_data['username'] = $this->username;
                    $post_data['pwd'] = $this->hashMd5();
                    $post_data['pmbh'] = $goods_info['goods_api_option']['pmbh'];
                    $post_data['pmmc'] = $goods_info['goods_api_option']['pmmc'];
                    $post_data['Xhbh'] = $goods_info['goods_api_option']['xhbh'];
                    $post_data['xhbh'] = $goods_info['goods_api_option']['xhbh'];
                    $post_data['xhmc'] = $goods_info['goods_api_option']['xhmc'];
                    $post_data['pjbh'] = $accessory_api['PJBH'];
                    $post_data['pjmc'] = $accessory_api['PJMC'];
                    $post_data['pjjg'] = $val['accessory_price'];
                    $post_data['bjyy'] = $jgsfyy;
                    $data['in0'] = json_encode($post_data);
                    $res = $this->soap_client->quotedpricePjByPjbh($data);
                    $get_data = json_decode($res->out, true);
                    echo '配件：' . $val['accessory_name'] . '，' . $get_data['resultMessage'] . '<br />';
                } else {
                    echo '配件：' . $val['accessory_name'] . '报价没变，不需要报价<br />';
                }
            }
        }
    }
    // 服务报价3.6
    public function sendServicePrice($goods_info)
    {
        echo '服务报价：<br />';
        if (! isset($goods_info['goods_service'])) {
            echo '没有服务报价';
        } else {
            $service_option = $goods_info['goods_service'];
            foreach ($service_option as $key => $val) {
                if (floatval($val['service_price']) != floatval($val['last_service_price'])) {
                    if (floatval($val['service_price']) > floatval($val['last_service_price'])) {
                        $jgsfyy = '正常报价';
                    } else {
                        $jgsfyy = '成本上涨';
                    }
                    $service_api = json_decode($val['service_api'], true);
                    $post_data['username'] = $this->username;
                    $post_data['pwd'] = $this->hashMd5();
                    $post_data['pmbh'] = $goods_info['goods_api_option']['pmbh'];
                    $post_data['pmmc'] = $goods_info['goods_api_option']['pmmc'];
                    $post_data['xhbh'] = $goods_info['goods_api_option']['xhbh'];
                    $post_data['xhmc'] = $goods_info['goods_api_option']['xhmc'];
                    $post_data['fwbh'] = $service_api['FWBH'];
                    $post_data['fwmc'] = $service_api['FWMC'];
                    $post_data['fwjg'] = $val['service_price'];
                    $post_data['bjyy'] = $jgsfyy;
                    $post_data['zt'] = 1;
                    $data['in0'] = json_encode($post_data);
                    $res = $this->soap_client->quotedpriceFwByFwbh($data);
                    $get_data = json_decode($res->out, true);
                    echo '服务：' . $val['service_name'] . '，' . $get_data['resultMessage'] . '<br />';
                } else {
                    echo '服务：' . $val['service_name'] . '报价没变，不需要报价<br />';
                }
            }
        }
    }
    // 订单查询3.8
    public function getDD()
    {
        define('PARTNER_ID', 25);
        define('MEMBER_ID', $this->member_id);
        define('SITE_ID', $this->ys_config['siteId']);
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['zt'] = '2';
        $post_data['kssj'] = date('YmdHis', time() - 100 * 86400);
        $post_data['jssj'] = date('YmdHis', time());
        if (isset($this->request['pageNum'])) {
            $post_data['pageNum'] = $this->request['pageNum'];
        } else {
            $post_data['pageNum'] = 1;
        }
        $post_data['pageSize'] = 20;
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->findOrder($data);
        $get_data = json_decode($res->out, true);
        dump($get_data['resultMessage']);
        // 创建订单
        if ($get_data['resultFlag'] == 'Y') {
            $orderdb = new Orderdb();
            $shoppingdb = new Shoppingdb();
            $invoicedb = new Invoicedb();
            $cartdb = new Cartdb();
            $goodsdb = new Goodsdb();
            foreach ($get_data['orderList'] as $key => $val) {
                $orderdb->param['out_order_no'] = $val['ddbh'];
                $orderdb->param['site_id'] = $this->ys_config['siteId'];
                $chk_order = $orderdb->ajaxFind();
                if ($chk_order != 'fail') {
                    echo '订单：' . $val['ddbh'] . '已存在<br />';
                    continue;
                }
                $order_data['order_no'] = $val['ddbh'];
                $order_data['out_order_no'] = $val['ddbh'];
                $order_data['api_param'] = json_encode($val);
                $order_data['order_money'] = $val['ddze'] * 100;
                $order_data['site_id'] = $this->ys_config['siteId'];
                $shoppingdb->param['province'] = '410000';
                $shoppingdb->param['city'] = '410100';
                $shoppingdb->param['area'] = '410101';
                $shoppingdb->param['street'] = $val['shdd'];
                $shoppingdb->param['contacts'] = $val['xflxrxm'];
                $shoppingdb->param['phone'] = $val['xfdh'];
                $shoppingdb->param['member_id'] = $this->member_id;
                $shoppingdb->param['is_default'] = 1;
                $get_shopping = $shoppingdb->ajaxSave();
                $order_data['shopping_id'] = $shoppingdb->last_id;
                $order_data['member_id'] = $this->member_id;
                $order_data['is_invoice'] = 2;
                $order_data['create_time'] = strtotime($val['cjrq']);
                $order_data['delivery_date'] = date('Y-m-d', strtotime('+ 3day', $order_data['create_time']));
                $order_data['order_member_id'] = $this->member_id;
                $order_data['remark'] = $val['beiz'];
                $cart_info = array();
                // 添加购物车
                $cartdb->param['order_no'] = '';
                foreach ($val['productList'] as $k => $v) {
                    $goodsdb->param['site_id'] = $this->ys_config['siteId'];
                    //$goodsdb->param['out_goods_sku'] = isset($v['goodsguid'])?$v['goodsguid']:$v['XHBH']; // 因为测试订单合采集产品不一致 这里用测试数据
                                                                        // $goodsdb->param['out_goods_sku'] = 'c31cdb088a474ef59dacb7fba25b2a40';
                    $goodsdb->param['out_goods_sku'] = $v['XHBH'];
                    $goods_info = $goodsdb->ajaxApiFind();
                    $cart_info[$k]['sale_attr_price_name'] = '商品价格';
                    $cart_info[$k]['site_id'] = $this->ys_config['siteId'];
                    $cart_info[$k]['category_sign'] = $goods_info['category_sign3'];
                    $cart_info[$k]['category_sign3'] = $goods_info['category_sign3'];
                    $cart_info[$k]['goods_sku'] = $goods_info['goods_sku'];
                    $cart_info[$k]['goods_attr_view'] = '默认属性';
                    $cart_info[$k]['goods_sale_price'] = $v['SJJG'];
                    $cart_info[$k]['goods_price'] = $v['SJJG'];
                    $cart_info[$k]['goods_market_price'] = $v['SJJG'];
                    $cart_info[$k]['sale_price'] = $v['SJJG'];
                    $cart_info[$k]['num'] = $v['SL'];
                    $cart_info[$k]['create_time'] = $order_data['create_time'];
                    $cart_info[$k]['member_id'] = $this->member_id;
                    $cart_info[$k]['sale_attr'] = '';
                    $cart_info[$k]['sale_attr_html'] = '';
                    $cart_info[$k]['api_option'] = json_encode($v);
                }
                $cartdb->param['cart_info'] = $cart_info;
                $cartdb->addCartHn();
                $order_data['cart_ids'] = $cartdb->inset_ids;
                $order_data['invoice_type'] = 1;
                $order_data['invoice_title'] = $val['fptt'];
                $order_data['invoice_duty'] = $val['nsrsbh'];
                $order_data['invoice_tel'] = '';
                $order_data['invoice_content'] = $val['fpnr'];
                $order_data['member_id'] = $this->member_id;
                $order_data['invoice_money'] = $order_data['order_money'];
                $order_data['cart_ids'] = $cartdb->inset_ids;
                $order_data['order_nos'] = $orderdb->last_order_no;
                $order_data['site_id'] = $this->ys_config['siteId'];
                $orderdb->param = $order_data;
                $orderdb->addOrder();
                echo '订单：' . $order_data['order_no'] . '录入成功<br />';
            }
            if ($get_data['pagecount'] > $post_data['pageNum']) {
                echo '3秒钟后采集下一页;';
                $url = url('henan/getDD', array(
                    'pageNum' => ($post_data['pageNum'] + 1)
                ));
                // header("Refresh:3;url=".$url);
            }
        }
    }
    // 确认订单3.9
    public function confirmOrder($out_order_no)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['ddbh'] = $out_order_no;
        $post_data['qrzt'] = 0;
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->execGysOrderQr($data);
        $get_data = json_decode($res->out, true);
        echo '确认订单' . $get_data['resultMessage'];
        dump($get_data);
    }
    // 物流信息3.10
    public function express($express_data, $out_order_no)
    {
        $express_info = $express_data[count($express_data) - 1];
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['ddbh'] = $out_order_no;
        $post_data['sfcd'] = 0; // 这里是拆单
        $post_data['fczddbh'] = $express_info['order_no'] . '_' . $express_info['express_id'];
        $post_data['kdgs'] = '北京优士创新科技发展有限公司';
        $post_data['kddh'] = $express_info['express_no'];
        $post_data['ms'] = '已发货';
        $post_data['kdsj'] = date('YmdHis', time() - 120);
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->exeLogistics($data);
        $get_data = json_decode($res->out, true);
        echo '物流信息：' . $get_data['resultMessage'] . '，时间：' . $post_data['kdsj'];
    }
    // 订单签收3.11
    public function signOrder($express_info, $out_order_no)
    {
        foreach ($express_info as $key => $val) {
            if ($val['receipt_state'] == 2) {
                $post_data['username'] = $this->username;
                $post_data['pwd'] = $this->hashMd5();
                $post_data['ddbh'] = $out_order_no;
                $post_data['sfcd'] = 0; // 这里是拆单
                $post_data['fczddbh'] = $val['order_no'] . '_' . $val['express_id'];
                $post_data['shsj'] = date('YmdHis', time() - 120);
                $data['in0'] = json_encode($post_data);
                $res = $this->soap_client->execQssj($data);
                $get_data = json_decode($res->out, true);
                dump($post_data);
                echo '订单签收信息：' . $get_data['resultMessage'] . '，时间：' . $post_data['shsj'];
            }
        }
    }
    // 订单发票信息3.12
    public function sendInvoice($out_order_no)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['ddbh'] = $out_order_no;
        $post_data['fpkjsj'] = date('YmdHis', time() - 120);
        dump($post_data);
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->execFpkjsjByOrder($data);
        $get_data = json_decode($res->out, true);
        echo '订单发票：' . $get_data['resultMessage'] . '，时间:' . $post_data['fpkjsj'];
    }
    // 收到订单发票时间3.13
    public function signInvoice($out_order_no)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['ddbh'] = $out_order_no;
        $post_data['fpsdsj'] = date('YmdHis', time() - 120);
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->execfpsdsjByorder($data);
        $get_data = json_decode($res->out, true);
        echo '推送收到发票时间：' . $get_data['resultMessage'] . '，时间：' . $post_data['fpsdsj'];
    }
    // 合同获取3.14
    public function getContract($out_order_no)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['ddbh'] = $out_order_no;
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->findOrderHt($data);
        $get_data = json_decode($res->out, true);
        echo '获取合同：' . $get_data['resultMessage'] . '，合同地址：' . $get_data['url'];
    }
    // 订单收款3.15
    public function orderPay($order_info)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['ddbh'] = $order_info['out_order_no'];
        $post_data['skbz'] = 1; // 这里是正常收款
        $post_data['skje'] = $order_info['order_money'];
        $post_data['sksj'] = date('YmdHis', time() - 120);
        $data['in0'] = json_encode($post_data);
        dump($post_data);
        $res = $this->soap_client->execSkqk($data);
        $get_data = json_decode($res->out, true);
        echo '订单收款：' . $get_data['resultMessage'] . '，时间：' . $post_data['sksj'];
    }
    // 订单取消3.16
    public function channelOrder($out_order_no)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['ddbh'] = $out_order_no;
        $post_data['qxyy'] = '取消说明';
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->execDsZfdd($data);
        $get_data = json_decode($res->out, true);
        echo '取消订单：' . $get_data['resultMessage'];
    }
    // 获取验收时间和验收方式3.17
    public function getOrderCheck($out_order_no)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['ddbh'] = $out_order_no;
        $data['in0'] = json_encode($post_data);
        dump($post_data);
        $res = $this->soap_client->findYsByOrder($data);
        $get_data = json_decode($res->out, true);
        dump($get_data);
        echo '订单验收情况：' . $get_data['resultMessage'];
    }
    // 商品上下架3.18
    public function goodsDown($goods_info)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['xhbh'] = $goods_info['goods_api_option']['xhbh'];
        $post_data['zt'] = 2;
        $post_data['xjyy'] = '北京优士创新科技发展有限公司';
        /*
         * if ($goods_info['sale_state'] == 2) {
         * $post_data['xjyy'] = $post_data['xjyy'].'商品无货，暂时下架<br />';
         * }
         */
        $data['in0'] = json_encode($post_data);
        dump($post_data);
        $res = $this->soap_client->execSpDown($data);
        $get_data = json_decode($res->out, true);
        echo '下架状态：<br />' . $get_data['resultMessage'] . '<br />';
    }
    // 商品上下架3.18
    public function goodsUp($goods_info)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['xhbh'] = $goods_info['goods_api_option']['xhbh'];
        $post_data['zt'] = 1;
        $post_data['xjyy'] = '北京优士创新科技发展有限公司';
        /*
         * if ($goods_info['sale_state'] == 2) {
         * $post_data['xjyy'] = $post_data['xjyy'].'商品无货，暂时下架<br />';
         * }
         */
        $data['in0'] = json_encode($post_data);
         //dump($post_data);
        $res = $this->soap_client->execSpDown($data);
        $get_data = json_decode($res->out, true);
        echo '上架状态：<br />' . $get_data['resultMessage'] . '<br />';
    }
    // 推送商品唯一识别码3.19 送货完成上传图片推送
    public function sendOrderPic($order_info, $express_info)
    {
        foreach ($express_info[0]['cart_list'] as $key => $val) {
            $temp = json_decode($val['api_option'], true);
            $xhbh = $val['goods_info']['api_option']['xhbh'];
            $post_data['username'] = $this->username;
            $post_data['pwd'] = $this->hashMd5();
            $post_data['ddbh'] = $order_info['out_order_no'];
            $post_data['xhbh'] = $temp['XHBH']; // 这里需要获取订单下产品的型号
            $post_data['wybs'] = $order_info['out_order_no'] . '_' . $express_info[0]['express_id'] . '北京优士创新科技发展有限公司';
            $img_src = $express_info[0]['express_proof']['save_path'];
            $post_data['pic'] = base64_encode(file_get_contents($img_src));
            $post_data['pid'] = $xhbh . $express_info[0]['express_proof']['upload_id'];
            $data['in0'] = json_encode($post_data);
            dump($post_data);
            $res = $this->soap_client->execTsWybs($data);
            $get_data = json_decode($res->out, true);
            echo '推送订单（型号：' . $temp['XHBH'] . '）（ 名称：' . $temp['XHMC'] . '）唯一识别码：' . $post_data['pid'] . chr(13);
        }
    }
    
    // 查询单个订单信息3.20
    public function getOrderInfo($out_order_info)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['ddbh'] = $out_order_info;
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->findDdxxByddbh($data);
        $get_data = json_decode($res->out, true);
        print_r($get_data);
    }
    // 获取商品型号信息3.21
    public function getGoodsInfo($goods_info)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['xhbh'] = $goods_info['goods_api_option']['xhbh'];
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->findSpByXhbh($data);
        $get_data = json_decode($res->out, true);
        dump($get_data);
        echo '获取单个商品型号：<br />' . $get_data['resultMessage'];
    }
    
    // 获取单个商品报价3.22
    public function getGoodsPrice($goods_info)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['xhbh'] = $goods_info['goods_api_option']['xhbh'];
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->findSpSfbj($data);
        $get_data = json_decode($res->out, true);
        dump($get_data);
        echo '获取单个商品报价：<br />' . $get_data['resultMessage'];
    }
    // 撤销商品报价3.23
    public function channelPrice($goods_info)
    {
        $post_data['username'] = $this->username;
        $post_data['pwd'] = $this->hashMd5();
        $post_data['xhbh'] = $goods_info['goods_api_option']['xhbh'];
        $data['in0'] = json_encode($post_data);
        $res = $this->soap_client->qxShByXhbh($data);
        $get_data = json_decode($res->out, true);
        dump($get_data);
        echo '撤销报价状态：<br />' . $get_data['resultMessage'];
    }

    protected function hashMd5()
    {
        return md5(md5($this->username . $this->username . $this->pwd, true));
    }

    protected function sendInfo($string_uri, $post)
    {
        $post['config'] = $this->ys_config;
        $json_data = json_encode($post);
        $postdatadb = new Postdatadb();
        $postdatadb->param['post_json'] = json_decode($json_data, true);
        $postdatadb->param['post_url'] = $string_uri;
        $postdatadb->ajaxSave();
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->ys_config['geteway'] . $string_uri);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "Content-type: application/json;charset='utf-8'"
        ));
        $result = curl_exec($ch);
        curl_close($ch);
        return json_decode($result, true);
    }
}